<template>
  <div class="card-detail">
    <div class="brand-top">
      <TitleBar title="品牌名片详情" bgColor="transparent" color="#fff"></TitleBar>
      <div class="card">
        <div class="title">
          <h6>{{cardTitle}}</h6>
          <div class="time">
            <img src="../../assets/img/time.png" alt="">
            <span class="time-text">更新时间</span>
            <span class="right-num">{{editdate}}</span>
          </div>
          <!-- <div class="read-num">
            <img src="../../assets/img/read-icon.png" alt="">
            <span class="read-text">阅读量</span>
            <span class="right-num">{{hits}}</span>
          </div> -->
        </div>
        <div class="logo" :style="{'background-image': 'url('+thumb+')'}">
        </div>
      </div>
    </div>
    <div class="brand-content">
      <Tab :tabtitles="tabs" :slidable="false" :animate="false" className="index-tab" ref="tab" @index="onTab">
        <div class="tab-container content">
          <div class="lines-bg"></div>
          <div class="text-content" ref="company">
            <div class="title">
              <span class="icon">
                <span class="sm-icon"></span>
              </span>
              <span class="text">公司介绍</span>
            </div>
            <p>公司名称: {{company}}</p>
            <p>成立时间: {{foundtime}}</p>
            <p>官方网址: {{homepage}}</p>
            <p>公司地址: {{address}}</p>
            <p>经营范围: {{business}}</p>
          </div>
          <div>
            <div class="text-content" v-for="(item, index) in contentList" :key="index" :id="'ref' + index" :ref="'ref' + index">
              <div class="title">
                <span class="icon">
                  <span class="sm-icon"></span>
                </span>
                <span class="text">{{item.name}}</span>
              </div>
              <p class="render-text" v-html="item.content"></p>
            </div>
          </div>
        </div>
      </Tab>
    </div>
    <ReturnItem></ReturnItem>
    <MyFooter :introduceShow="true"></MyFooter>
  </div>
</template>
<script>
import TitleBar from '../../components/TitleBar'
import MyFooter from '../../components/MyFooter'
import Tab from '../../components/VueTab'
import ReturnItem from './components/ReturnItem'
import * as events from '../../store/events'
export default {
  components: {
    TitleBar,
    MyFooter,
    Tab,
    ReturnItem
  },
  data() {
    return {
      tabs: ['公司介绍'],
      cardTitle: null, // 品牌名称
      editdate: null, // 更新日期
      // hits: null, // 阅读量	
      thumb: null, // LOGO
      company: null, // 公司名称
      foundtime: null, // 成立时间
      homepage: null, // 公司网址
      address: null, // 公司地址
      business: null, // 经营范围
      contentList: [] // 其它介绍
    }
  },
  mounted() {
    this.$showLoading()
    this.getCardDetail()
  },
  methods: {
    onTab(e) {
      // if (e == 1) {
      //   this.$refs.company.scrollIntoView(true)
      // }
      if (e == 2) {
        this.$nextTick(() => {
          this.$refs.ref0[0].scrollIntoView(true)
        })
      }
      if (e == 3) {
        this.$nextTick(() => {
          this.$refs.ref1[0].scrollIntoView(true)
        })
      }
    },
    getCardDetail() {
      this.$api.postCardDetail(this.$route.params.itemid).then(data => {
        this.$hideLoading()
        if (data.data.status == 1) {
          // 活动宗旨内容
          let cardInfo = data.data.cardInfo
          // 客服联系方式
          let setting = data.data.setting
          this.cardTitle = cardInfo.title
          this.editdate = cardInfo.editdate
          // this.hits = cardInfo.hits
          this.thumb = cardInfo.thumb
          this.company = cardInfo.company
          this.foundtime = cardInfo.foundtime
          this.homepage = cardInfo.homepage
          this.address = cardInfo.address
          this.business = cardInfo.business
          // 有品牌简介 
          if (cardInfo.introduce) {
            // 添加 tab名称
            this.tabs.push('品牌简介')
            // 添加品牌简介内容
            this.contentList.push({
              name: '品牌简介',
              content: cardInfo.introduce
            })
            // 判断是否其他介绍内容
            if (data.data.contents.length) {
              // 取第一条name
              this.tabs.push(data.data.contents[0].name)
              data.data.contents.forEach((item) => {
                this.contentList.push(item)
              })
            }
          } else {
            // 无品牌简介
            if (data.data.contents.length) {
              // 取两条
              data.data.contents.forEach((item, index) => {
                if (index < 2) {
                  this.tabs.push(item.name)
                }
                this.contentList.push(item)
              })
            }
          }
          // 客服数据
          let service = {
            email: data.data.setting.service_email,
            tel: data.data.setting.service_tel
          }
          // 客服数据存到store中
          this.$store.commit(events.SET_SERVICE_INFO, service)
        } else {
          this.$toast.center(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>
<style lang="scss">
.card-detail {
  .index-tab {
    .tab-title {
      font-size: 0.28rem;
      color: rgba(102, 102, 102, 1);
      &.active,
      &:active {
        font-size: 0.36rem;
        font-weight: 700;
        color: rgba(34, 34, 34, 1);
        background-color: transparent;
        span {
          position: absolute;
          width: 0.4rem;
          height: 0.12rem;
          border-radius: 0.06rem;
          background: rgba(255, 215, 77, 1);
          bottom: 0;
          left: 50%;
          transform: translate3d(-0.2rem, 0, 0);
        }
      }
    }
    .tab-title-container {
      width: 5.9rem;
    }
    .tab-container {
      margin-top: 0.08rem;
      background-color: #f6f6f6;
      border-radius: 0.2rem 0.2rem 0 0;
      padding-bottom: 0.3rem;
    }
  }
}
</style>
<style lang='scss' scoped>
.card-detail {
  width: 100%;
  min-height: 100vh;
  background-color: #d8b577;
  .brand-top {
    width: 100%;
    height: 5.11rem;
    background: url("../../assets/img/brand-card-bg.png") center no-repeat;
    background-size: cover;
  }
  .card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0.3rem;
    margin-top: 0.36rem;
    .title {
      width: 4.2rem;
      h6 {
        font-size: 0.4rem;
        line-height: 0.46rem;
        color: rgba(255, 255, 255, 1);
        margin-bottom: 0.3rem;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        /* autoprefixer: ignore next */
        -webkit-box-orient: vertical;
      }
      .time-text {
        font-size: 0.24rem;
        line-height: 0.24rem;
        color: rgba(255, 255, 255, 1);
        margin-left: 0.15rem;
        margin-right: 0.38rem;
      }
      .read-text {
        font-size: 0.24rem;
        line-height: 0.24rem;
        color: rgba(255, 255, 255, 1);
        letter-spacing: 0.08rem;
        margin-left: 0.15rem;
        margin-right: 0.38rem;
      }
      .right-num {
        font-size: 0.24rem;
        line-height: 0.24rem;
        color: rgba(255, 255, 255, 1);
      }
      .time {
        display: inline-block;
        min-width: 3.5rem;
        max-width: 100%;
        height: 0.36rem;
        line-height: 0.36rem;
        background: rgba(32, 32, 40, 0.16);
        border-radius: 0.18rem;
        margin-bottom: 0.1rem;
      }
      .read-num {
        display: inline-block;
        min-width: 2.8rem;
        height: 0.36rem;
        line-height: 0.36rem;
        background: rgba(32, 32, 40, 0.16);
        border-radius: 0.18rem;
      }
      img {
        width: 0.26rem;
        height: 0.26rem;
        margin: 0 0.1rem;
        vertical-align: middle;
      }
    }
    .logo {
      width: 2.58rem;
      height: 1.6rem;
      border-radius: 0.04rem;
      background: center no-repeat;
      background-size: contain;
    }
  }
  .brand-content {
    width: 6.9rem;
    background: rgba(255, 255, 255, 1);
    border-radius: 0.16rem;
    margin: -1.8rem auto 0.3rem;
    padding: 0.2rem 0;
    .content {
      background-color: #fff;
      border-radius: 0;
      padding: 0 0.5rem;
      .lines-bg {
        width: 5.9rem;
        height: 0.1rem;
        background: url("../../assets/img/brand-card-line.png") center no-repeat;
        background-size: cover;
        margin: 0.2rem auto 0.4rem;
      }
      .text-content {
        margin-bottom: 0.7rem;
        .title {
          margin-bottom: 0.3rem;
          .icon {
            display: inline-block;
            vertical-align: text-top;
            width: 0.2rem;
            height: 0.2rem;
            background: rgba(255, 215, 77, 0.5);
            border-radius: 0.02rem;
            position: relative;
            .sm-icon {
              width: 0.16rem;
              height: 0.16rem;
              background: rgba(255, 215, 77, 1);
              border-radius: 0.02rem;
              position: absolute;
              bottom: -0.1rem;
              right: -0.1rem;
            }
          }
          .text {
            font-size: 0.3rem;
            font-weight: bold;
            color: rgba(34, 34, 34, 1);
            margin-left: 0.24rem;
          }
        }
        .dynamic {
          text-indent: 0.44rem;
          font-size: 0.28rem;
          line-height: 0.48rem;
          color: rgba(34, 34, 34, 1);
        }
        p {
          text-indent: 0.44rem;
          font-size: 0.28rem;
          line-height: 0.48rem;
          color: rgba(34, 34, 34, 1);
          word-break: break-all;
        }
      }
    }
  }
}
</style>
